<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 2.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Ineo - Modules - Admin CP Overview
*
* @package		Ineo
* @subpackage   Modules
* @copyright	2006, Veriea
*/
class ineo_mod_acp_logs
{
	/**
	* Variable Setup
	*/
	var $ipsclass;
	var $core;
	
	/**
	* Initialize
	*/
	function module_init()
	{
		// ACP Module, Do nothing if not in ACP!
		if( !IN_ACP )
		{
			return false;
		}
	}
	
	/**
	* Default Function for this module:
	*/
	function module_default()
	{
		return $this->logs();
	}
	
	function logs()
	{
		$this->ipsclass->admin->page_title = 'Ineo Moderator Logs';
		$this->ipsclass->admin->page_detail = 'This page allows you to view the latest moderator actions in Ineo.';
	
  		// Count the number of friggin' logs, yarr.
  		$this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ineo_logs' );
  		$this->ipsclass->DB->simple_exec();
  		$count = $this->ipsclass->DB->fetch_row();

		$_START = intval( $this->ipsclass->input['st'] );
  
		$links = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $count['cnt'],
	                                                  'PER_PAGE' => 20,
	                                                  'CUR_ST_VAL' => $_START,
	                                                  'BASE_URL'    => $this->ipsclass->base_url.'&section=components&act=ineo&code=logs',) );
	
		$rows = $this->get_logs($_START);
	
		$this->core->api->box( 'Moderator Logs', $rows );
		$this->ipsclass->html .= $links;
	}

	/**
	* Get moderator logs from the db, pass an offset and suchlike:
	*/
	function get_logs( $offset )
	{
		$this->ipsclass->DB->simple_construct( 
											array(
												
												'select' => 'l.*,m.members_display_name', 
												'from' => array('ineo_logs'=>'l'),
												'add_join' => array(
																	
																	1 => array(
																				
																				'type' => 'left',
																				'from' => array('members'=>'m'),
																				'where' => 'm.id = l.member_id',
																			
																				)
																	
																	)
												) 
										);
		$offset = ( $offset == '' ) ? 0 : $offset;
		$this->ipsclass->DB->simple_order('id DESC');
		$this->ipsclass->DB->simple_limit($offset, 20);
		$this->ipsclass->DB->simple_exec();
  
  		$rows = '<table style="border-spacing: 0px" width="100%" cellspacing="0" cellpadding="5" style="margin: 0px">
           <tr>
           <td class="' . $this->core->api->thead . '" align="center">Act</td>
           <td class="' . $this->core->api->thead . '" align="center">Code</td>
           <td class="' . $this->core->api->thead . '" align="center">Note</td>
           <td class="' . $this->core->api->thead . '" align="center">Member</td>
           <td class="' . $this->core->api->thead . '" align="center">Time</td>
           <td class="' . $this->core->api->thead . '" align="center">IP Address</td>
         </tr>';
  
		while ( $log = $this->ipsclass->DB->fetch_row() )
		{
  			$rows .= '<tr>
              <td class="'.$this->core->api->row1.'" valign="middle">'.$log['act'].'</td>
              <td class="'.$this->core->api->row2.'" valign="middle">'.$log['code'].'</td>
              <td class="'.$this->core->api->row1.'" valign="middle">'.$log['note'].'</td>
              <td class="'.$this->core->api->row2.'" valign="middle">'.$log['members_display_name'].'</td>
              <td class="'.$this->core->api->row1.'" valign="middle">'.$this->ipsclass->get_date($log['time'],'').'</b></td>
              <td class="'.$this->core->api->row1.'" valign="middle">'.$log['ip_address'].'</td>
            </tr>';
		}

		$rows .= '</table>';
	
		return $rows;
	}

}

?>